using System;

namespace AuthService.Options;

/// <summary>
/// Keycloak配置选项
/// </summary>
public class KeycloakOptions
{
    public const string SectionName = "Keycloak";

    /// <summary>
    /// 服务器URL
    /// </summary>
    public string ServerUrl { get; set; } = "http://localhost:8080";

    /// <summary>
    /// 管理员用户名
    /// </summary>
    public string AdminUsername { get; set; } = "admin";

    /// <summary>
    /// 管理员密码
    /// </summary>
    public string AdminPassword { get; set; } = string.Empty;

    /// <summary>
    /// 默认Realm
    /// </summary>
    public string DefaultRealm { get; set; } = "master";

    /// <summary>
    /// 请求超时时间（秒）
    /// </summary>
    public int RequestTimeout { get; set; } = 30;

    /// <summary>
    /// 客户端配置
    /// </summary>
    public ClientConfig Client { get; set; } = new();

    /// <summary>
    /// 缓存配置
    /// </summary>
    public CacheConfig Cache { get; set; } = new();

    /// <summary>
    /// 重试配置
    /// </summary>
    public RetryConfig Retry { get; set; } = new();
}

/// <summary>
/// 客户端配置
/// </summary>
public class ClientConfig
{
    /// <summary>
    /// 客户端ID
    /// </summary>
    public string ClientId { get; set; } = "matrix-admin-cli";

    /// <summary>
    /// 客户端密钥
    /// </summary>
    public string ClientSecret { get; set; } = string.Empty;

    /// <summary>
    /// 授权类型
    /// </summary>
    public string GrantType { get; set; } = "client_credentials";

    /// <summary>
    /// 作用域
    /// </summary>
    public List<string> Scopes { get; set; } = new() { "openid", "profile", "email" };
}

/// <summary>
/// 缓存配置
/// </summary>
public class CacheConfig
{
    /// <summary>
    /// 是否启用缓存
    /// </summary>
    public bool Enabled { get; set; } = true;

    /// <summary>
    /// 绝对过期时间（分钟）
    /// </summary>
    public int AbsoluteExpirationMinutes { get; set; } = 60;

    /// <summary>
    /// 滑动过期时间（分钟）
    /// </summary>
    public int SlidingExpirationMinutes { get; set; } = 30;

    /// <summary>
    /// 大小限制
    /// </summary>
    public int SizeLimit { get; set; } = 1000;
}

/// <summary>
/// 重试配置
/// </summary>
public class RetryConfig
{
    /// <summary>
    /// 最大重试次数
    /// </summary>
    public int MaxAttempts { get; set; } = 3;

    /// <summary>
    /// 初始延迟（毫秒）
    /// </summary>
    public int InitialDelayMilliseconds { get; set; } = 1000;

    /// <summary>
    /// 退避倍数
    /// </summary>
    public double BackoffMultiplier { get; set; } = 2.0;
}